package cn.dt70.service.impl;

import cn.dt70.dao.aqbInterest.AqbInterestMapper;
import cn.dt70.pojo.AqbInterest;
import cn.dt70.pojo.AqbInterestandcode;
import cn.dt70.service.AqbInterestService;
import cn.dt70.utils.PageSupport;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("AqbInterestService")
public class AqbInterestServiceImpl implements AqbInterestService {

    private static final Logger LOGGER = Logger.getLogger(AqbInterestServiceImpl.class);

    @Resource
    private AqbInterestMapper aqbInterestMapper;

    @Override
    public boolean addInterest(Integer uid, AqbInterestandcode itc) {
        boolean flag = false;
        try {
            int row = aqbInterestMapper.addInterest(uid,itc);
            if(row == 1){
                LOGGER.debug("AqbInterestServiceImpl.addInterest  添加成功》》》");
                flag = true;
            }else{
                LOGGER.debug("AqbInterestServiceImpl.addInterest  添加失败》》》");
            }
        } catch (Exception e) {
//            e.printStackTrace();
            LOGGER.error("AqbInterestServiceImpl.addInterest  添加异常》》》"+e.getMessage());
        }
        return flag;
    }

    @Override
    public List<AqbInterest> getAllByUid(Integer uid, Integer status, PageSupport ps) {
        List<AqbInterest> aqbInterestList = new ArrayList<AqbInterest>();
        try {
            ps.setTotalCount(aqbInterestMapper.getNumber(uid, status));
            aqbInterestList = aqbInterestMapper.getAllByUid(uid,status,(ps.getCurrentPageNo()-1)*ps.getPageSize(),ps.getPageSize());
            if(null == aqbInterestList || ("").equals(aqbInterestList)){
                LOGGER.debug("AqbInterestServiceImpl.getAllByUid  查询失败》》》");
            }else{
                LOGGER.debug("AqbInterestServiceImpl.getAllByUid  查询成功》》》");
            }
        } catch (Exception e) {
//            e.printStackTrace();
            LOGGER.error("AqbInterestServiceImpl.getAllByUid  查询异常》》》"+e.getMessage());
        }
        return aqbInterestList;
    }

    @Override
    public boolean changeStatus(Integer uid, Integer valueId, Integer status) {
        boolean flag = false;
        try {
            int row = aqbInterestMapper.changeStatus(uid, valueId, status);
            if(row == 1){
                flag = true;
                LOGGER.debug("AqbInterestServiceImpl.changeStatus  修改成功》》》");
            }else{
                LOGGER.debug("AqbInterestServiceImpl.changeStatus  修改失败》》》");
            }
        } catch (Exception e) {
//            e.printStackTrace();
            LOGGER.error("AqbInterestServiceImpl.changeStatus  修改异常》》》"+e.getMessage());
        }
        return flag;
    }
}
